package com.example.demo.finitestatemachine.machine;

import com.example.demo.finitestatemachine.state.LiftState;
import com.example.demo.finitestatemachine.state.LiftStateCodeEnums;
import com.example.demo.finitestatemachine.transition.ArrivedTransition;
import com.example.demo.finitestatemachine.transition.ClosingTransition;
import com.example.demo.finitestatemachine.transition.OpeningTransition;
import com.example.demo.finitestatemachine.transition.RunningTransition;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liyuncong
 * @version 1.0
 * @file LiftStateMachine
 * @brief LiftStateMachine
 * @details LiftStateMachine
 * @date 2022-12-28
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-12-28                  liyuncong          Created
 */
public class LiftStateMachine extends LiftAbstractStateMachine {

    @Override
    public List<LiftState> declareAllStates() {
        List<LiftState> states = new ArrayList<>();

        final LiftState openState = new LiftState(LiftStateCodeEnums.OPEN);
        final LiftState closeState = new LiftState(LiftStateCodeEnums.CLOSE);
        final LiftState runState = new LiftState(LiftStateCodeEnums.RUN);
        final LiftState stopState = new LiftState(LiftStateCodeEnums.STOP);

        // 开门状态 添加 关门动作
        openState.addTransition(new ClosingTransition(openState, closeState));
        // 关门状态 添加 开门动作、运行动作
        closeState.addTransition(new OpeningTransition(closeState, openState));
        closeState.addTransition(new RunningTransition(closeState, runState));
        // 运行状态 添加 到达动作
        runState.addTransition(new ArrivedTransition(runState, stopState));
        // 停止状态 添加 开门状态、运行状态
        stopState.addTransition(new OpeningTransition(stopState, openState));
        stopState.addTransition(new RunningTransition(stopState, runState));

        states.add(openState);
        states.add(closeState);
        states.add(runState);
        states.add(stopState);
        return states;
    }


}
